package com.majsubtense.core;

import com.majsubtense.core.components.UI;
import com.majsubtense.core.events.*;

import javafx.scene.Scene;

/**
 * @brief 暂时做成单例类，接收外部输入，将输入包装成 Event 对象，然后通知所有的监听者.
 */
public class InputStream extends Notifier {
    /**
     * @param gameScene: 暂时作为外部输入的来源.
     * @brief 将输入包装成 Event 对象，然后通知所有的监听者.
     * @retval void.
     */
    public static void activateInput(GameScene gameScene) {
        Scene scene = gameScene.getComponent(UI.ANY).getScene();
        // Key pressed event.
        scene.setOnKeyPressed(event ->
                onDeliver(new KeyboardEvent(KeyboardEvent.KEYBOARD_PRESSED, event))
        );
        // Key released event.
        scene.setOnKeyReleased(event ->
                onDeliver(new KeyboardEvent(KeyboardEvent.KEYBOARD_RELEASED, event))
        );
    }
}
